// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import { PostponeApplyList } from '../domains/postponeApply.domain';
import { PayRecord } from '../domains/PayRecord.domain';

/**
 *
 */
@Injectable({
  providedIn: 'root'
})
export class PostponeApplyServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'PostponeApplyServiceSvr.assx/';
  }


  getMaxDays(token: string, customerId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString());
    return this.request.post<number>(this.baseUrl + 'getMaxDays', httpParams).then((res) => {
      return res;
    });
  }


  deletePostponeApply(token: string, postponeApplyId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('postponeApplyId', postponeApplyId.toString());
    return this.request.post<number>(this.baseUrl + 'deletePostponeApply', httpParams).then((res) => {
      return res;
    });
  }


  updatePostponeApply(token: string, postponeApplyId: string, status: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('postponeApplyId', postponeApplyId.toString())
      .append('status', status.toString());
    return this.request.post<number>(this.baseUrl + 'updatePostponeApply', httpParams).then((res) => {
      return res;
    });
  }


  listPostponeApply(token: string, status: number, payRecordId: string, customerId: string, customerName: string, postponeApplyId: string, skip: number, size: number): Promise<PostponeApplyList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('status', status.toString())
      .append('payRecordId', payRecordId.toString())
      .append('customerId', customerId.toString())
      .append('customerName', customerName.toString())
      .append('postponeApplyId', postponeApplyId.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<PostponeApplyList>(this.baseUrl + 'listPostponeApply', httpParams).then((res) => {
      return res;
    });
  }


  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }


  savePostponeApply(token: string, payRecordId: string, description: string, days: string): Promise<PayRecord> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('payRecordId', payRecordId.toString())
      .append('description', description.toString())
      .append('days', days.toString());
    return this.request.post<PayRecord>(this.baseUrl + 'savePostponeApply', httpParams).then((res) => {
      return res;
    });
  }


  getPostponeApplyListSize(token: string, customerId: string, customerName: string, status: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('customerName', customerName.toString())
      .append('status', status.toString());
    return this.request.post<number>(this.baseUrl + 'getPostponeApplyListSize', httpParams).then((res) => {
      return res;
    });
  }
}
